package com.studorm;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;

public final class XMLOption {

	public static Document loadXML(String fileName) throws DocumentException{
		File file = new File(fileName);
		SAXReader reader = new SAXReader();
		Document document = null;
		document = reader.read(file);

		return document;
	}

	public static void writeXml(Document document, String filePath) throws IOException  
	{  
		File file = new File(filePath);  
		XMLWriter writer = null;  

		if(file.exists())  
		{  
			file.delete();  
		}  
		writer = new XMLWriter(new FileOutputStream(file));  
		writer.write(document);  
		writer.close();  

	}
}
